﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
  public  class CommentsService
    {


        //有图新增
      public static bool AddimgComments(Comments cm)
        {
            SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Cm_UsId",cm.Cm_UsId), new SqlParameter("@Cm_GmId",cm.Cm_GmId),
            new SqlParameter("@Cm_Title",cm.Cm_Title),new SqlParameter("@Cm_Image",cm.Cm_Image),new SqlParameter("@Cm_Desc",cm.Cm_Desc),
            new SqlParameter("@Cm_Date",cm.Cm_Date)};
            return DBHelper.Instance().ExcuteProcedure("up_AddimgComments", para);
        }
      //无图新增
      public static bool AddComments(Comments cm)
      {
          SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Cm_UsId",cm.Cm_UsId), new SqlParameter("@Cm_GmId",cm.Cm_GmId),
            new SqlParameter("@Cm_Title",cm.Cm_Title),new SqlParameter("@Cm_Desc",cm.Cm_Desc),
            new SqlParameter("@Cm_Date",cm.Cm_Date)};
          return DBHelper.Instance().ExcuteProcedure("up_AddComments", para);
      }

        //删除
      public static bool DeleComments(int id)
        {
            SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Cm_Id", id) };
            return DBHelper.Instance().ExcuteProcedure("up_DeleComments", para);
        }
      //删除指定游戏id评论
      public static bool DeleGmIdComments(int id)
      {
          SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Cm_GmId", id) };
          return DBHelper.Instance().ExcuteProcedure("up_DeleGmIdComments", para);
      }
      //删除指定用户评论
      public static bool DeleUsidComments(int id)
      {
          SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Cm_UsId", id) };
          return DBHelper.Instance().ExcuteProcedure("up_DeleUsidComments", para);
      }

        //修改指定全部内容
      public static bool UpdaComments(Comments cm)
        {
            SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Cm_UsId",cm.Cm_UsId), new SqlParameter("@Cm_GmId",cm.Cm_GmId),
            new SqlParameter("@Cm_Title",cm.Cm_Title),new SqlParameter("@Cm_Image",cm.Cm_Image),new SqlParameter("@Cm_Desc",cm.Cm_Desc),
            new SqlParameter("@Cm_Date",cm.Cm_Date), new SqlParameter("@Cm_Id",cm.Cm_Id)};
            return DBHelper.Instance().ExcuteProcedure("up_UpdaComments", para);
        }
        //日期倒序查询所有信息
      public static List<Comments> SeleAllComments()
        {
            List<Comments> item = new List<Comments>();
            string sql = string.Format("select * from Comments order by Cm_Date desc ");
            DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Comments cm = new Comments();
                    cm.Cm_Id = Convert.ToInt32(dt.Rows[i]["Cm_Id"].ToString());
                    cm.Cm_UsId = Convert.ToInt32(dt.Rows[i]["Cm_UsId"].ToString());
                    cm.Cm_GmId = Convert.ToInt32(dt.Rows[i]["Cm_GmId"].ToString());
                    cm.Cm_Title = dt.Rows[i]["Cm_Title"].ToString();
                    cm.Cm_Image = dt.Rows[i]["Cm_Image"].ToString();
                    cm.Cm_Desc = dt.Rows[i]["Cm_Desc"].ToString();
                    cm.Cm_Date = Convert.ToDateTime(dt.Rows[i]["Cm_Date"].ToString());
                    item.Add(cm);
                }
            }
            return item;
        }
        //查指定id信息
      public static List<Comments> SeleIdComments(int id)
        {
            List<Comments> item = new List<Comments>();
            string sql = string.Format("select * from Comments where Cm_Id='{0}'",id);
            DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Comments cm = new Comments();
                    cm.Cm_Id = Convert.ToInt32(dt.Rows[i]["Cm_Id"].ToString());
                    cm.Cm_UsId = Convert.ToInt32(dt.Rows[i]["Cm_UsId"].ToString());
                    cm.Cm_GmId = Convert.ToInt32(dt.Rows[i]["Cm_GmId"].ToString());
                    cm.Cm_Title = dt.Rows[i]["Cm_Title"].ToString();
                    cm.Cm_Image = dt.Rows[i]["Cm_Image"].ToString();
                    cm.Cm_Desc = dt.Rows[i]["Cm_Desc"].ToString();
                    cm.Cm_Date = Convert.ToDateTime(dt.Rows[i]["Cm_Date"].ToString());
                    item.Add(cm);
                }
            }
            return item;
        }

      //游戏id查询信息
      public static List<Comments> SeleGameIdComments(int gmid)
      {
          List<Comments> item = new List<Comments>();
          string sql = string.Format("select * from Comments where Cm_GmId='{0}'",gmid);
          DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
          if (dt != null && dt.Rows.Count > 0)
          {
              for (int i = 0; i < dt.Rows.Count; i++)
              {
                  Comments cm = new Comments();
                  cm.Cm_Id = Convert.ToInt32(dt.Rows[i]["Cm_Id"].ToString());
                  cm.Cm_UsId = Convert.ToInt32(dt.Rows[i]["Cm_UsId"].ToString());
                  cm.Cm_GmId = Convert.ToInt32(dt.Rows[i]["Cm_GmId"].ToString());
                  cm.Cm_Title = dt.Rows[i]["Cm_Title"].ToString();
                  cm.Cm_Image = dt.Rows[i]["Cm_Image"].ToString();
                  cm.Cm_Desc = dt.Rows[i]["Cm_Desc"].ToString();
                  cm.Cm_Date = Convert.ToDateTime(dt.Rows[i]["Cm_Date"].ToString());
                  item.Add(cm);
              }
          }
          return item;
      }


      //查游戏名信息
      public static List<Comments> SeleLikeGameNameComments(string name)
      {
          List<Comments> item = new List<Comments>();
          string sql = string.Format("select * from Comments where Cm_Title like '%{0}%'", name);
          DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
          if (dt != null && dt.Rows.Count > 0)
          {
              for (int i = 0; i < dt.Rows.Count; i++)
              {
                  Comments cm = new Comments();
                  cm.Cm_Id = Convert.ToInt32(dt.Rows[i]["Cm_Id"].ToString());
                  cm.Cm_UsId = Convert.ToInt32(dt.Rows[i]["Cm_UsId"].ToString());
                  cm.Cm_GmId = Convert.ToInt32(dt.Rows[i]["Cm_GmId"].ToString());
                  cm.Cm_Title = dt.Rows[i]["Cm_Title"].ToString();
                  cm.Cm_Image = dt.Rows[i]["Cm_Image"].ToString();
                  cm.Cm_Desc = dt.Rows[i]["Cm_Desc"].ToString();
                  cm.Cm_Date = Convert.ToDateTime(dt.Rows[i]["Cm_Date"].ToString());
                  item.Add(cm);
              }
          }
          return item;
      }

      //查指定用户id信息
      public static List<Comments> SeleUsIdComments(int id)
      {
          List<Comments> item = new List<Comments>();
          string sql = string.Format("select * from Comments where Cm_UsId='{0}'", id);
          DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
          if (dt != null && dt.Rows.Count > 0)
          {
              for (int i = 0; i < dt.Rows.Count; i++)
              {
                  Comments cm = new Comments();
                  cm.Cm_Id = Convert.ToInt32(dt.Rows[i]["Cm_Id"].ToString());
                  cm.Cm_UsId = Convert.ToInt32(dt.Rows[i]["Cm_UsId"].ToString());
                  cm.Cm_GmId = Convert.ToInt32(dt.Rows[i]["Cm_GmId"].ToString());
                  cm.Cm_Title = dt.Rows[i]["Cm_Title"].ToString();
                  cm.Cm_Image = dt.Rows[i]["Cm_Image"].ToString();
                  cm.Cm_Desc = dt.Rows[i]["Cm_Desc"].ToString();
                  cm.Cm_Date = Convert.ToDateTime(dt.Rows[i]["Cm_Date"].ToString());
                  item.Add(cm);
              }
          }
          return item;
      }


    }
}
